<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:rich="http://richfaces.org/rich" template="layout/template.xhtml">

	<ui:define name="body">

		<h:form id="inventorySearch" styleClass="edit">

			<rich:simpleTogglePanel label="Inventory search parameters"
				switchType="ajax">


				<s:decorate template="layout/display.xhtml">
					<ui:define name="label">Card</ui:define>
					<h:inputText id="cardName" value="#{inventoryList.card.cardName}" />
				</s:decorate>
				<s:decorate template="layout/display.xhtml">
					<ui:define name="label">User firstname</ui:define>
					<h:inputText id="firstName" value="#{inventoryList.user.firstName}" />
				</s:decorate>
				<s:decorate template="layout/display.xhtml">
					<ui:define name="label">User lastname</ui:define>
					<h:inputText id="lastName" value="#{inventoryList.user.lastName}" />
				</s:decorate>
				<s:decorate template="layout/display.xhtml">
					<ui:define name="label">Note</ui:define>
					<h:inputText id="note" value="#{inventoryList.inventory.note}" />
				</s:decorate>

			</rich:simpleTogglePanel>

			<div class="actionButtons"><h:commandButton id="search"
				value="Search" action="/InventoryList.xhtml" /></div>

		</h:form>

		<h:form>
			<rich:panel>
				<f:facet name="header">Inventory search results</f:facet>
				<div class="results" id="inventoryList"><h:outputText
					value="No cards found" rendered="#{empty inventoryList.resultList}" />
				<rich:dataTable id="inventoryList" var="inventory"
					value="#{inventoryList.resultList}"
					rendered="#{not empty inventoryList.resultList}" style="width:90%;">
	
					<h:column>
						<f:facet name="header">Owner</f:facet>
	            #{inventory.user.firstName} #{inventory.user.lastName}
	        </h:column>
					<h:column>
						<f:facet name="header">
							<s:link styleClass="columnHeader"
								value="Card #{inventoryList.order=='card.cardName asc' ? messages.down : ( inventoryList.order=='card.cardName desc' ? messages.up : '' )}">
								<f:param name="order"
									value="#{inventoryList.order=='card.cardName asc' ? 'card.cardName desc' : 'card.cardName asc'}" />
							</s:link>
						</f:facet>
	            #{inventory.card.cardName}
	        </h:column>
					<h:column>
						<f:facet name="header">Edition</f:facet>
	            #{inventory.card.edition.name}
	        </h:column>
					<h:column>
						<f:facet name="header">Foil</f:facet>
	            #{inventory.card.foil.description}
	        </h:column>
					<h:column>
						<f:facet name="header">
							<s:link styleClass="columnHeader"
								value="Owned #{inventoryList.order=='have asc' ? messages.down : ( inventoryList.order=='have desc' ? messages.up : '' )}">
								<f:param name="order"
									value="#{inventoryList.order=='have asc' ? 'have desc' : 'have asc'}" />
							</s:link>
						</f:facet>
	            #{inventory.have}
	        </h:column>
					<h:column>
						<f:facet name="header">
							<s:link styleClass="columnHeader"
								value="Keep #{inventoryList.order=='keep asc' ? messages.down : ( inventoryList.order=='keep desc' ? messages.up : '' )}">
								<f:param name="order"
									value="#{inventoryList.order=='keep asc' ? 'keep desc' : 'keep asc'}" />
							</s:link>
						</f:facet>
	            #{inventory.keep}
	        </h:column>
	                <h:column>
	                    <f:facet name="header">For Trade</f:facet>
	            #{inventory.forTrade}
	        </h:column>
	                <h:column>
	                    <f:facet name="header">Wanted</f:facet>
	            #{inventory.wanted}
	        </h:column>
					<h:column>
						<f:facet name="header">
							<s:link styleClass="columnHeader"
								value="Buy-price #{inventoryList.order=='buyAmount asc' ? messages.down : ( inventoryList.order=='buyAmount desc' ? messages.up : '' )}">
								<f:param name="order"
									value="#{inventoryList.order=='buyAmount asc' ? 'buyAmount desc' : 'buyAmount asc'}" />
							</s:link>
						</f:facet>
	            #{inventory.buyAmount}
	        </h:column>
					<h:column>
						<f:facet name="header">
							<s:link styleClass="columnHeader"
								value="Sell-price #{inventoryList.order=='sellAmount asc' ? messages.down : ( inventoryList.order=='sellAmount desc' ? messages.up : '' )}">
								<f:param name="order"
									value="#{inventoryList.order=='sellAmount asc' ? 'sellAmount desc' : 'sellAmount asc'}" />
							</s:link>
						</f:facet>
	            #{inventory.sellAmount}
	        </h:column>
					<h:column>
						<f:facet name="header">Total spent</f:facet>
	            #{inventory.totalAmount}
	        </h:column>
					<h:column>
						<f:facet name="header">Note</f:facet>
	            #{inventory.note}
	        </h:column>
					<h:column>
						<f:facet name="header">action</f:facet>
						<s:button view="/#{empty from ? 'Inventory' : from}.xhtml"
							value="Select" id="inventory">
							<f:param name="inventoryId" value="#{inventory.id}" />
						</s:button>
						<s:button view="/InventoryEdit.xhtml" id="edit" value="Edit">
							<f:param name="inventoryId" value="#{inventory.id}" />
						</s:button>
					</h:column>
						<f:facet name="footer">
							<rich:datascroller></rich:datascroller>
						</f:facet>
				</rich:dataTable></div>
			</rich:panel>
		</h:form>

		<!-- div class="tableControl"><s:link view="/InventoryList.xhtml"
			rendered="#{inventoryList.previousExists}"
			value="#{messages.left}#{messages.left} First Page" id="firstPage">
			<f:param name="firstResult" value="0" />
		</s:link> <s:link view="/InventoryList.xhtml"
			rendered="#{inventoryList.previousExists}"
			value="#{messages.left} Previous Page" id="previousPage">
			<f:param name="firstResult"
				value="#{inventoryList.previousFirstResult}" />
		</s:link> <s:link view="/InventoryList.xhtml"
			rendered="#{inventoryList.nextExists}"
			value="Next Page #{messages.right}" id="nextPage">
			<f:param name="firstResult" value="#{inventoryList.nextFirstResult}" />
		</s:link> <s:link view="/InventoryList.xhtml"
			rendered="#{inventoryList.nextExists}"
			value="Last Page #{messages.right}#{messages.right}" id="lastPage">
			<f:param name="firstResult" value="#{inventoryList.lastFirstResult}" />
		</s:link></div -->

		<s:div styleClass="actionButtons" rendered="#{empty from}">
			<s:button view="/InventoryEdit.xhtml" id="create"
				value="Create inventory">
				<f:param name="inventoryId" />
			</s:button>
		</s:div>

	</ui:define>

</ui:composition>

